
/*
 * jQuery File Upload Plugin JS Example 8.9.1
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */

/* global $, window */

$(function () {
    'use strict';
/*
    // Initialize the jQuery File Upload widget:
    $('#fileupload').fileupload({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
        url: "/api/upload/file?pid="+currentProject.id
    });

    // Enable iframe cross-domain access via redirect option:
    $('#fileupload').fileupload(
        'option',
        'redirect',
        window.location.href.replace(
            /\/[^\/]*$/,
            '/cors/result.html?%s'
        )
    );

   
	// Load existing files:
	$('#fileupload').addClass('fileupload-processing');
	$.ajax({
		// Uncomment the following to send cross-domain cookies:
		//xhrFields: {withCredentials: true},
		// url: $('#fileupload').fileupload('option', 'url'),
		url: $('#fileupload').fileupload('option', 'url'),
		dataType: 'json',
		context: $('#fileupload')[0]
	}).always(function () {
		$(this).removeClass('fileupload-processing');
	}).done(function (result) {
		console.log(result);
		$(this).fileupload('option', 'done').call(this, $.Event('done'), {result: result});
	});
    */

	
	
	$('#fileupload')
    .bind('fileuploadadd', function (e, data) {
	
	})
    .bind('fileuploadsubmit', function (e, data) {
	
	})
    .bind('fileuploadsend', function (e, data) {
	
	})
    .bind('fileuploaddone', function (e, data) {
		var data = data.result;
		$.each(data.files, function (index, file) {
			console.log('Selected file: ' + file.name);
			$.post("/api/upload/extract?id="+currentProject.id,{name:file.name},function(data){
				if(data.error){
					showStickyErrorToast(data.message);
				}else{
					
					$("#status1").append("File upload Done<br>");         
					
					$("#stencils-holder").html("");
					for(var i=0;i<=data.data.length;i++){
						
						caseProject.renderItemProject(data.data[i]);
					}
					
				}
			});
		});
	})
    .bind('fileuploadfail', function (e, data) {
	
	})
    .bind('fileuploadalways', function (e, data) {
	
	})
    .bind('fileuploadprogress', function (e, data) {
	
	})
    .bind('fileuploadprogressall', function (e, data) {
	
	})
    .bind('fileuploadstart', function (e) {
	
	})
    .bind('fileuploadstop', function (e) {
	
	})
    .bind('fileuploadchange', function (e, data) {
	
	})
    .bind('fileuploadpaste', function (e, data) {
	
	})
    .bind('fileuploaddrop', function (e, data) {
	
	})
    .bind('fileuploaddragover', function (e) {
	
	})
    .bind('fileuploadchunksend', function (e, data) {
	
	})
    .bind('fileuploadchunkdone', function (e, data) {
	
	})
    .bind('fileuploadchunkfail', function (e, data) {
	
	})
    .bind('fileuploadchunkalways', function (e, data) {
	
	});
});


